package ua.epam.muzalevskiy.traction.logger;

import java.io.File;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.PropertyConfigurator;

/**
 * <code>Log4jInit</code> class configures log4j logger.
 *
 * @author Muzalevskiy Vitaliy
 */
public class Log4jInit implements ServletContextListener {

    /**
     * Invokes before servlet context is destroyed.
     *
     * @param contextEvent event reference
     */
    public void contextDestroyed(ServletContextEvent contextEvent) {
    }

    /**
     * Invokes after servlet context is initialized.
     *
     * @param contextEvent event reference
     */
    public void contextInitialized(ServletContextEvent contextEvent) {
        //defines the properties file with log4j logger configurations
        String homeDir = contextEvent.getServletContext().getRealPath("/");
        File propertiesFile = new File(homeDir, "WEB-INF/log4j.properties");
        PropertyConfigurator.configure(propertiesFile.toString());
    }
}
